package com.yy.salary.excel;

import com.github.crab2died.ExcelUtils;

import com.yy.salary.model.Salary;
import org.apache.log4j.Logger;

import java.util.List;


public class LoadService<T> {
    private static Logger logger = Logger.getLogger(LoadService.class);

    private T t;

    public LoadService(T t) {
        this.t = t;
    }

    public <T>List<T> loadKPExcel(String path){
        // 2)
        // 基于注解,将Excel内容读至List<Student2>对象内
        // 验证读取转换函数Student2ExpelConverter
        // 注解 `@ExcelField(title = "是否开除", order = 5, readConverter =  Student2ExpelConverter.class)`
        List<T> kpLoadVOs = null;
        try {
            kpLoadVOs = (List<T>) ExcelUtils.getInstance().readExcel2Objects(path, t.getClass(), 0, 0);
        } catch (Exception e) {
            logger.error("读取发票excel文件失败,请检查该{"+path+"}路径下,是否存在文件",e);
            System.exit(1);
        }
        return kpLoadVOs;

    }

    public static void main(String[] args) {
        LoadService<Salary> salaryLoadService = new LoadService<Salary>(new Salary());
        List<Salary> classes = salaryLoadService.loadKPExcel("E:\\发放模板.xls");
        classes.stream().forEach(salary -> System.out.println(salary.toString()) );
    }
}
